package com.briup.pai.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * ClassName：RedisUtil
 *
 * @Author：小鱼
 * @Create：2025-10-29 11:10
 */
//手动控制redis中数据的存取
    @Component
public class RedisUtil {
    //准备redisTemplate对象
    @Autowired
    private RedisTemplate redisTemplate;

    //set方法
    public  void set(String key, Object value, long expireTime) {
        redisTemplate.opsForValue().set(key, value, expireTime, TimeUnit.SECONDS);
    }

    //get方法
    public  Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    //remove
    public  boolean remove(String key) {
        return redisTemplate.delete(key);
    }

    //exist
    public  boolean exist(String key) {
        return redisTemplate.hasKey(key);
    }
}
